﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;
using Xoohoo.Extensions;

namespace Xoohoo.Utilities.Cryptography
{
    /// <summary>
    /// MD5加密算法
    /// </summary>
    public static class MD5
    {
        public static byte[] EncryptToByteArray(byte[] inputByteArray)
        {
            MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
            return provider.ComputeHash(inputByteArray);
        }
        public static byte[] EncryptToByteArray(string encryptString)
        {
            if (encryptString.IsNullOrWhiteSpace()) return null;

            byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);

            return EncryptToByteArray(inputByteArray);
        }
        public static string Encrypt(string encryptString)
        {
            if (encryptString.IsNullOrWhiteSpace()) return null;

            byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);

            return Encrypt(inputByteArray);
        }
        public static string Encrypt(byte[] inputByteArray)
        {
            return Convert.ToBase64String(EncryptToByteArray(inputByteArray));
        }

    }
}
